param(
    [switch]$UpdateAbp,
    [switch]$UpdateDeps,
    [switch]$Pack,
    [switch]$Push,
    [switch]$Commit,
    [switch]$Test,
    [switch]$SetKey,
    [switch]$Normalize
)

function Ask-YesNo($message, $default=$true) {
    $defaultText = if ($default) { "[Y/n]" } else { "[y/N]" }
    $input = Read-Host "$message $defaultText"
    if ([string]::IsNullOrWhiteSpace($input)) { return $default }
    return $input.ToLower().StartsWith("y")
}

function Show-Menu {
    Write-Host ""
    Write-Host "请选择要执行的操作："
    Write-Host "1. 备份分支（abp版本+项目版本）"
    Write-Host "2. 升级依赖（abp和其它）"
    Write-Host "3. 打包"
    Write-Host "4. 推送到 NuGet"
    Write-Host "5. 运行单元测试"
    Write-Host "6. 设置推送 API Key"
    Write-Host "7. 规范化所有项目"
    Write-Host "0. 退出"
}

while ($true) {
    Show-Menu
    $choice = Read-Host "请输入操作编号"
    switch ($choice) {
        "1" {
            # 备份分支（只创建分支不切换）
            $commonProps = Get-Content "$PSScriptRoot/../common.props" -Raw
            if ($commonProps -match '<AbpVersion>([\d\.]+)</AbpVersion>') { $abp = $matches[1] } else { $abp = "unknown" }
            $branch = "abp-$abp"
            git branch $branch
            git add .
            git commit -m "chore: backup branch for abp $abp"
            git push origin $branch
            Write-Host "已备份分支: $branch（当前仍在主线）"
        }
        "2" {
            & "$PSScriptRoot/update-abp-version.ps1"
            & "$PSScriptRoot/update-deps.ps1"
        }
        "3" { & "$PSScriptRoot/pack-all.ps1" }
        "4" { & "$PSScriptRoot/push-all.ps1" }
        "5" { & "$PSScriptRoot/unit_test.ps1" }
        "6" { & "$PSScriptRoot/set_pack_api_key.cmd" }
        "7" { & "$PSScriptRoot/update-projects.ps1" }
        "0" { Write-Host "已退出。"; break }
        default { Write-Host "无效选择，请重新输入。" }
    }
} 